/*
 *  Copyright 2013 HCIWriter
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.hci.writer.client.place;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.hci.writer.client.Storage;
import com.hci.writer.shared.Task;

public class WritePlace extends Place {

	private Task task = null;

	public WritePlace(String token) {
		this.task = Storage.participant.getTask(token);
		
		if(this.task == null) {
			throw new RuntimeException("Task not found!");
		}
    }
	
	public WritePlace(Task task) {
		this.task = task;
		
		if(this.task == null) {
			throw new RuntimeException("Task not found!");
		}
    }

    public Task getTask() {
        return this.task;
    }

    public static class Tokenizer implements PlaceTokenizer<WritePlace> {
        @Override
        public String getToken(WritePlace place) {
            return place.getTask().getClassName();
        }

        @Override
        public WritePlace getPlace(String token) {
            return new WritePlace(token);
        }
    }
    
}
